#include <iostream>
#include "EpollServer.hpp"
#include "Listener.hpp"
#include "Connection.hpp"
int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }
    int port = std::stoi(argv[1]);
    Listener listener(port);
    listener.Init();
    connection_t conn = std::make_shared<Connection>(listener.ListenSockfd());
    conn->InsertMethod([&](){
        InetAddr peer;
        int newsockfd = listener.Accepter(&peer);
        //newsockfd TODO
        conn->SetPeerAddrInfo(peer);
    },nullptr,nullptr);
    
    EpollServer epoll_server;
    epoll_server.Init();
    epoll_server.InsertConnection(conn->Sockfd(),conn);
    epoll_server.Loop();
    return 0;
}